# -*- coding = utf-8 -*-
# @Time    : 2025/4/14 上午9:20
# @Author  : yqk
# @File    : 常见加密算法.py
# @Software: PyCharm
from hashlib import md5, sha1, sha256, sha512

obj = md5()
text = '123456'.encode('utf-8')  # 将字符串编码为字节
obj.update(text)
encrypt_text = obj.hexdigest()  # 转换为16进制字符串
print(encrypt_text, len(encrypt_text))
#e10adc3949ba59abbe56e057f20f883e 32

import base64
s = '中文'.encode('utf-8')  # b'\xe4\xb8\xad\xe6\x96\x87'
s_64 = base64.b64encode(s)  # b'5Lit5paH'
s_64_decode = base64.b64decode(s_64).decode('utf-8')  # '中文'

print(s, s_64, s_64_decode)
# 输出：b'\xe4\xb8\xad\xe6\x96\x87' b'5Lit5paH' 中文